<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="公司名字" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入公司名字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人名字" label-width="100px" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入业务联系人名字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人手机号" label-width="100px" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系人手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['men:menCooperateInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['men:menCooperateInfo:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['men:menCooperateInfo:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['men:menCooperateInfo:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="menCooperateInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="咨询合作id" align="center" prop="id" /> -->
      <el-table-column
        label="技术类型"
        align="center"
        prop="skillType"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="技术服务"
        align="center"
        prop="skillService"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="行业"
        align="center"
        prop="trade"
        :show-overflow-tooltip="true"
      />
      <!--      <el-table-column label="公司地址" align="center" prop="address" :show-overflow-tooltip="true"/>-->
      <el-table-column
        label="业务介绍"
        align="center"
        prop="intro"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="需求描述"
        align="center"
        prop="need"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="客户类型"
        align="center"
        prop="customerType"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="公司名字"
        align="center"
        prop="companyName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="联系人名字"
        width="100px"
        align="center"
        prop="name"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="联系人手机号"
        width="100px"
        align="center"
        prop="phone"
        :show-overflow-tooltip="true"
      />
      <!--      <el-table-column label="邮箱" align="center" prop="email" :show-overflow-tooltip="true"/>-->
      <el-table-column label="创建时间" align="center" prop="caAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.caAt) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="修改时间" align="center" prop="upAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.upAt) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['men:menCooperateInfo:edit']"
          >修改</el-button> -->

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDeail(scope.row)"
            v-hasPermi="['men:menCooperateInfo:edit']"
            >详情</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['men:menCooperateInfo:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改咨询与合作对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="技术类型" prop="skillType">
          <el-select v-model="form.skillType" placeholder="请选择技术类型">
            <el-option
              v-for="item in skillTypeOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="技术服务" prop="skillService">
          <el-select v-model="form.skillService" placeholder="请选择技术服务">
            <!--            <el-option label="请选择字典生成" value="" />-->
            <el-option
              v-for="item in skillServiceOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="行业" prop="trade">
          <el-select v-model="form.trade" placeholder="请选择行业">
            <!--            <el-option label="请选择字典生成" value="" />-->
            <el-option
              v-for="item in tradeOptions"
              :key="item.id"
              :label="item.trade"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公司地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入公司地址" />
        </el-form-item>
        <el-form-item label="业务介绍" prop="intro">
          <el-input
            v-model="form.intro"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="需求描述" prop="need">
          <el-input
            v-model="form.need"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="客户类型" prop="customerType">
          <el-select v-model="form.customerType" placeholder="请选择客户类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="公司名字" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名字" />
        </el-form-item>
        <el-form-item label="业务联系人名字" prop="name">
          <el-input v-model="form.name" placeholder="请输入业务联系人名字" />
        </el-form-item>
        <el-form-item label="联系人手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系人手机号" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="创建时间" prop="caAt">
          <el-date-picker
            clearable
            size="small"
            v-model="form.caAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间"
          >
          </el-date-picker>
        </el-form-item>
        <!--        <el-form-item label="修改时间" prop="upAt">-->
        <!--          <el-date-picker clearable size="small"-->
        <!--            v-model="form.upAt"-->
        <!--            type="date"-->
        <!--            value-format="yyyy-MM-dd"-->
        <!--            placeholder="选择修改时间">-->
        <!--          </el-date-picker>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="0默认1删除" prop="delFlag">-->
        <!--          <el-input v-model="form.delFlag" placeholder="请输入0默认1删除" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listMenCooperateInfo,
  getMenCooperateInfo,
  delMenCooperateInfo,
  addMenCooperateInfo,
  updateMenCooperateInfo,
  exportMenCooperateInfo,
} from "@/api/men/menCooperateInfo";

export default {
  name: "MenCooperateInfo",
  components: {},
  data() {
    return {
      skillTypeOptions: [],
      skillServiceOptions: [],
      tradeOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 咨询与合作表格数据
      menCooperateInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: null,
        name: null,
        phone: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        skillType: [
          { required: true, message: "技术类型不能为空", trigger: "change" },
        ],
        skillService: [
          { required: true, message: "技术服务不能为空", trigger: "change" },
        ],
        trade: [{ required: true, message: "行业不能为空", trigger: "change" }],
        intro: [
          { required: true, message: "业务介绍不能为空", trigger: "blur" },
        ],
        need: [
          { required: true, message: "需求描述不能为空", trigger: "blur" },
        ],
        customerType: [
          { required: true, message: "客户类型不能为空", trigger: "change" },
        ],
        name: [
          {
            required: true,
            message: "业务联系人名字不能为空",
            trigger: "blur",
          },
        ],
        phone: [
          { required: true, message: "联系人手机号不能为空", trigger: "blur" },
        ],
        email: [{ required: true, message: "邮箱不能为空", trigger: "blur" }],
        caAt: [
          { required: true, message: "创建时间不能为空", trigger: "blur" },
        ],
        delFlag: [
          { required: true, message: "0默认1删除不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询咨询与合作列表 */
    getList() {
      this.loading = true;
      listMenCooperateInfo(this.queryParams).then((response) => {
        this.menCooperateInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        skillType: null,
        skillService: null,
        trade: null,
        address: null,
        intro: null,
        need: null,
        customerType: null,
        companyName: null,
        name: null,
        phone: null,
        email: null,
        caAt: null,
        upAt: null,
        delFlag: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加咨询与合作";
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids;
    //   getMenCooperateInfo(id).then((response) => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改咨询与合作";
    //   });
    // },
    /** 详情按钮操作 */
    handleDeail(row) {
      this.reset();
      const id = row.id || this.ids;
      getMenCooperateInfo(id).then((response) => {
        this.form = response.data;
        this.skillTypeOptions = response.classList;
        this.skillServiceOptions = response.classList;
        this.tradeOptions = response.classList;
        this.open = true;
        this.title = "咨询与合作详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateMenCooperateInfo(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMenCooperateInfo(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除咨询与合作选中数据", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delMenCooperateInfo(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有咨询与合作数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportMenCooperateInfo(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
